<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .smallimg {
        width: 300px;
        height: 300px;
        position: absolute;
        background: url(../day23作业/imgs/1.jpg) no-repeat center / 100%;
      }
      .small {
        width: 100px;
        height: 100px;
        background: cornflowerblue;
        opacity: 0.3;
        display: none;
        position: absolute;
      }
      .big {
        width: 300px;
        height: 300px;
        position: absolute;
        left: 300px;
        overflow: hidden;
        display: none;
      }
      .bigimg {
        width: 900px;
        height: 900px;
        position: absolute;
      }
    </style>
  </head>
  <body>
    <div class="smallimg">
      <div class="small"></div>
    </div>
    <div class="big">
      <img src="../day23作业/imgs/1.jpg" alt="" class="bigimg" />
    </div>

    <script>
      var smallimg = document.querySelector(".smallimg");
      var small = document.querySelector(".small");
      var big = document.querySelector(".big");
      var bigimg = document.querySelector(".bigimg");
      var last = document.querySelectorAll(".last");
      smallimg.onmouseover = function () {
        small.style.display = "block";
        big.style.display = "block";
      };
      smallimg.onmouseout = function () {
        small.style.display = "none";
        big.style.display = "none";
      };
      small.onmousemove = function (e) {
        var e = e.event || window.event;
        var x = e.clientX - 50;
        var y = e.clientY - 50;
        if (x >= 200) {
          x = 200;
        }
        if (x <= 0) {
          x = 0;
        }
        if (y >= 200) {
          y = 200;
        }
        if (y <= 0) {
          y = 0;
        }
        small.style.top = y + "px";
        small.style.left = x + "px";
        bigimg.style.top = -3 * y + "px";
        bigimg.style.left = -3 * x + "px";
      };
    </script>
  </body>
</html>
